#include <iostream>
#include <map>
#include <string>
#include <utility>

using namespace std;

void map_init() { map<int, string> m; }

void map_destroy() {
  map<int, string> m;
  m.clear();
}

void map_query() {
  map<int, string> m;

  m[1] = "abc";
  m[2] = "bc";

  map<int, string>::iterator fd = m.find(1);
  if (fd != m.end()) {

    cout << "frist: " << fd->first << ", "
         << "second: " << fd->second << endl;
  } else {
    cout << "not found" << endl;
  }
}

void map_insert() {
  map<int, string> m;

  // will overwrite exist
  m[1] = "abc";
  m[2] = "bc";

  // will reserver exist
  m.insert(make_pair(3, "ccc"));
  m.insert(map<int, string>::value_type(4, "ddd"));
}

void map_update() {
  map<int, string> m;
  m[1] = "abc";
  m[2] = "bc";
}

void map_delete() {
  map<int, string> m;
  m[1] = "abc";
  m[2] = "bc";
  m[3] = "bcd";

  map<int, string>::iterator fd = m.find(2);
  m.erase(fd);

  for (map<int, string>::iterator it = m.begin(); it != m.end(); it++) {
    cout << it->first << it->second << endl;
  }
}

void map_iter() {
  map<int, string> m;
  m[1] = "abc";
  m[2] = "bc";
  m[3] = "bcd";

  for (map<int, string>::iterator it = m.begin(); it != m.end(); it++) {
    cout << it->first << it->second << endl;
  }
}

void map_size() {
  map<int, string> m;
  m[1] = "abc";
  m[2] = "bc";
  m[3] = "bcd";

  cout << m.size() << endl;
}

int main() {

  map_init();
  map_query();
  map_insert();
  map_update();
  map_delete();
  map_iter();
  return 0;
}
